<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      span {
        user-select: none;
        cursor: default;
        font-size: 20px;
        color: blue;
        position: absolute;
        transition: 1s;
      }
    </style>
  </head>
  <body>
    <!-- ⿏标点击⻚⾯出现随机颜⾊的⽂字，出现之后向上淡出 -->
    <script>
      // 设置随机出现的文字数组
      var arr = ['出现了出现了', '又出现了', '又又又出现了', '真是太6了', '永远自由呦']
      document.onclick = function (x) {
        // 创建元素节点对象
        var span = document.createElement('span')
        // 获取当前鼠标的坐标
        span.style.left = x.clientX + 'px'
        span.style.top = x.clientY + 'px'
        // 让span的值为arr数组内随机的一个值
        span.innerHTML = arr[Math.floor(Math.random() * arr.length)]
        // 设置span的动画效果
        setTimeout(function () {
          span.style.opacity = '1'
          span.style.transform = 'translateY(-200px)'
        }, 100)
        setTimeout(function () {
          span.style.opacity = '0'
        }, 1500)
        // 清掉opacort为0的span
        var chi = document.getElementsByClassName('span')
        for (var i = 0; i < chi.length; i++) {
          if (chi[i].style.opacity === '0') {
            document.body.removeChild(chi[i])
          }
        }
        // 将span添加到body里
        document.body.appendChild(span)
      }
    </script>
  </body>
</html>
